using System.Collections.Generic;
using Project.Configs;
using Project.Models;
using Project.ViewModels;
using Project.Views;
using UnityEngine;

namespace Project.EntryPoints
{
    public class SceneEntryPoint : MonoBehaviour
    {
        private InputControls _inputControls;
        private List<Character> _characters;
        private RootScreenViewModel _rootScreenViewModel;

        [SerializeField] private CharacterConfig[] _characterConfigs;
        [Space]
        [SerializeField] private RootScreenView _rootScreenView;

        private void Awake()
        {
            InitializeInputControls();
            InitializeCharacters();
            InitializeViewModels();
            InitializeViews();
        }

        private void InitializeInputControls()
        {
            _inputControls = new InputControls();
            _inputControls.Enable();
        }

        private void InitializeCharacters()
        {
            _characters = new List<Character>(_characterConfigs.Length);

            foreach (var characterConfig in _characterConfigs)
                _characters.Add(new Character(characterConfig));
        }

        private void InitializeViewModels()
        {
            _rootScreenViewModel = new RootScreenViewModel(_inputControls, _characters, _characterConfigs);
        }

        private void InitializeViews()
        {
            _rootScreenView.Initialize(_rootScreenViewModel);
        }
    }
}
